
import requests
from bs4 import BeautifulSoup
# 获取user-agent,用于身份识别
header = {'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Mobile Safari/537.36'}



# 获取虎嗅热点新闻的URL
url = 'https://www.huxiu.com/moment/'


# 发送HTTP请求
response = requests.get(url,headers=header)

# 确保请求成功
if response.status_code == 200:
    print(response.text)
    # 解析HTML内容
    soup = BeautifulSoup(response.text, 'html.parser')

    # 找到所有的新闻标题和链接
    news_items = soup.select('.news-list-item a')

    # 打印每条新闻的标题和链接
    for item in news_items:
        print('标题:', item.text.strip())
        print('链接:', item.get('href'))
        print()  # 空行分隔不同新闻
else:
    print('请求失败')